
#include <iostream>

#include <gtest/gtest.h>

#include <byteorder.hpp>

template<typename T>
void test_swap_byteorer(T n1, T n2)
{
	T n1_r = kb::swap_byteorder(n1);
	ASSERT_EQ(n2, n1_r);

	T n2_r = kb::swap_byteorder(n2);
	ASSERT_EQ(n1, n2_r);
}

struct obj_t {
	int32_t i1;
	uint32_t i2;

	obj_t(int32_t n1, uint32_t n2)
		: i1(n1)
		, i2(n2) {}

	bool operator==(const obj_t &o) const {
		return (i1 == o.i1)
			&& (i2 == o.i2);
	}
};

TEST(test_byteorder, swap_byteorder)
{
	signed char c1 = 0x12;
	const signed char c2 = 0x12;
	test_swap_byteorer(c1, c2);

	const unsigned char uc1 = 0xef;
	unsigned char uc2 = 0xef;
	test_swap_byteorer(uc1, uc2);

	signed short s1 = 0x1234;
	signed short s2 = 0x3412;
	test_swap_byteorer(s1, s2);

	const unsigned short us1 = 0xcdef;
	const unsigned short us2 = 0xefcd;
	test_swap_byteorer(us1, us2);

	int32_t i1 = 0x12345678;
	int32_t i2 = 0x78563412;
	test_swap_byteorer(i1, i2);

	const uint32_t ui1 = 0xabcdef01U;
	uint32_t ui2 = 0x01efcdabU;
	test_swap_byteorer(ui1, ui2);

	const int64_t l1 = 0x1234567890abcdefULL;
	int64_t l2 = 0xefcdab9078563412ULL;
	test_swap_byteorer(l1, l2);

	uint64_t ul1 = 0xabcdef1234567890ULL;
	const uint64_t ul2 = 0x9078563412efcdabULL;
	test_swap_byteorer(ul1, ul2);
	
	//show compile error if uncommented this
	// obj_t o1(0x12345678, 0x90abcdefU);
	// obj_t o2(0xefdcab90, 0x78563412U);
	// test_swap_byteorer(o1, o2);
}

TEST(test_byteorder, byteorder_cast)
{
}
